<?php if($pager->getNbResults() && ( $pager->getFirstPage() != $pager->getLastPage() )):?>
<?php 
	$width = 2;
	$total = $pager->getLastPage();
	$curPage = $pager->getPage();

	if( $curPage - $width > 0 && $curPage + $width <= $total ){
		$start = $curPage-$width;
	}else if( $curPage - $width < 1 && $curPage + $width <= $total ){
		$start = 1;
	}else if( $curPage - $width > 1 && $curPage + $width > $total ){
		$start = $curPage-$width-1;
	}else{
		$start = 1;
	}	
?>

<div style="width:<?php echo $total*10 + 55 ?>px;margin:auto;" >
	<div style="display:inline; padding: 1px 1px"><a href="<?php echo LinkGen::getInstance(LinkGen::PRODUCT_GROUP)->link($category['id'], array('page' => 1)) ?>"><img src="/project_css_js/img/vasakule_loppu.png" /></a></div>
	<div style="display:inline; padding: 1px 1px"><a href="<?php echo $sf_request->getParameter('page',1) != 1 ? LinkGen::getInstance(LinkGen::PRODUCT_GROUP)->link($category['id'], array('page' => $sf_request->getParameter('page') - 1)) : "#" ?>"><img src="/project_css_js/img/vasakule.png" /></a></div>
	<?php for($i = $start; $i <= $pager->getLastPage() && ($i - $start+1) <= ($width * 2 + 1); ++$i):?>
	<span style="font-size:14px" class="<?php echo $sf_request->getParameter('page',1) == $i  ? 'active superactive' : '' ?>">
		<?php if($sf_request->getParameter('page',1) == $i): ?>
			<b><?php echo $i ?></b>
		<?php else: ?>
			<a style="font-size: 14px;" href="<?php echo LinkGen::getInstance(LinkGen::PRODUCT_GROUP)->link($category['id'], array('page' => $i)) ?>"><?php echo $i ?></a>
		<?php endif; ?>

	</span>
	<?php endfor;?>
	<div style="display:inline; padding: 1px 1px"><a href="<?php echo $sf_request->getParameter('page',1) != $total ? LinkGen::getInstance(LinkGen::PRODUCT_GROUP)->link($category['id'], array('page' => $sf_request->getParameter('page') + 1)) : "#" ?>"><img src="/project_css_js/img/paremale.png" /></a></div>
	<div style="display:inline; padding: 1px 1px"><a href="<?php echo LinkGen::getInstance(LinkGen::PRODUCT_GROUP)->link($category['id'], array('page' => $total)) ?>"><img src="/project_css_js/img/paremale_loppu.png" /></a></div>
</div>
<?php endif;?>
